//package com.gaofei.task.job;
//
//import cn.hutool.json.JSONObject;
//import cn.hutool.json.JSONUtil;
//import com.alipay.api.AlipayApiException;
//import com.alipay.api.AlipayClient;
//import com.alipay.api.AlipayConfig;
//import com.alipay.api.DefaultAlipayClient;
//import com.alipay.api.domain.AlipayTradeQueryModel;
//import com.alipay.api.request.AlipayTradeQueryRequest;
//import com.alipay.api.response.AlipayTradeQueryResponse;
//import com.xxl.job.core.handler.annotation.XxlJob;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//@Component
//@Slf4j
//public class PayBillBatchJob {
//
//    /**
//     * 定时跑批对账
//     * @throws AlipayApiException
//     */
//    @XxlJob("searchPayBillFromAliPay")
//    public void searchPayBillFromAliPay() throws AlipayApiException {
//        //1.从支付数据库中查询订单支付状态(调用支付宝api完成)
//        String body = searchOrderFromAlipay();
//        //1.1 将这个body(String),转成json
//        JSONObject entries = JSONUtil.parseObj(body);
//        JSONObject alipay_trade_query_response = (JSONObject) entries.get("alipay_trade_query_response");
//        String outTradeNo = (String) alipay_trade_query_response.get("out_trade_no");
////        Double totalAmount = (Double) alipay_trade_query_response.get("total_amount");
//        String tradeStatus = (String) alipay_trade_query_response.get("trade_status");
//        //2.从自己数据库(jd,后台)查询咱们的订单
//        Order order = oderService.getOne(outTradeNo);
//        //3.如果订单金额,或者订单交易状态不一致,保存到日志当中
//        if (tradeStatus.equals("TRADE_SUCCESS"))  {
//            if(order.getPayStatus()==0){//未支付
//                //正常的逻辑需要修改的.题目没有要求,直接记录日志了
//                log.info("此订单是异常,订单编号为:{}",outTradeNo);
//            }
//        }
//    }
//
//    public String searchOrderFromAlipay() throws AlipayApiException {
//        String privateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCspZuyimkZ0hG441eITVVQyeCfwV9BgTpDocDC7IG85gHqDFiORIsKyDKPH7O0GFAHFH4bE99o8vSfTsMFPqVmQ2Y2YgkR80wCkWkJ8GNA0CNF+Cscx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VHGouSZRgXTKKon8rX0QQKBgQCe+46Ld/k1xyPL7ffCoIVyzE4139YTclwl90GjBbXLJkuvn8vnWOgnAmMX+iow1aVMft5t864P/17cOT69z00hpZhhMXatG3KWoBVVUCNdMmX7rlkyqy6evNiPR2KdO1Vl9FBkVWc/IfMYnk/Zz5Yfnq2dCQTEeAd6NoDj76om2QKBgH0VC3I9Nf1BJ8StoLsLi7lCoWfORPH519KqLt7tGv6yHb/bnwIoDKwbfkQCnnBOwC+ADuPyhgVVqGqmUuersyFdTXLp1G0+9xXQNyh6iTYaAmwUZr3XEP/EJIlXgRAg9P/hHok19nWLoUpikY8oRGY8JtOIwgQ5/TqLIA46Zsga";
//        String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAio0KicEvQ/8404EWznkT1MCvomH3iVIYnrHRVXtL3xFXfRBxRBe5GTzbDLhayz1g+a/nYShUDaSYRcpdeqr9koQTwg8946JB5wC/SFcMFQdxdu4lyR+ZiyGI9bRgevZKqYyyc4n6nb0xLghpgPIcaQOwFLHRkiFh0jQwcTX0uuF4YTvxiYTFQk1oQKU1elfemhF4bqAq/K1xPhAtNxMPxH9HokGMklyf9a3e8gPtBy1dOv7g0yB7V5HuUR+88MgCUYjaN9Hx1LtMeP0I8YAOMSxQ4xBKOG3GPzy6rkvr68gdt1y25qKaqJWDJMSpzgbjFy2tltJGUEGx+rsA0ZWjkwIDAQAB";
//        AlipayConfig alipayConfig = new AlipayConfig();
//        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
//        alipayConfig.setAppId("9021000126621192");
//        alipayConfig.setPrivateKey(privateKey);
//        alipayConfig.setFormat("json");
//        alipayConfig.setAlipayPublicKey(alipayPublicKey);
//        alipayConfig.setCharset("UTF-8");
//        alipayConfig.setSignType("RSA2");
//        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
//        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
//        AlipayTradeQueryModel model = new AlipayTradeQueryModel();
//        model.setOutTradeNo("9999");
//        request.setBizModel(model);
//        AlipayTradeQueryResponse response = alipayClient.execute(request);
//        System.out.println(response.getBody());
//        String body = response.getBody();
//        if (response.isSuccess()) {
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
//            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
//            // System.out.println(diagnosisUrl);
//        }
//        return body;
//    }
//}
